from flask import Blueprint, Response, request
from ..model.User import User
from ..dal import UserDAL,UserVDAL

user = Blueprint('user', __name__)

@user.route('/getuserv')
def getUserV():
    # 获取参数
    uid = request.args.get("uid")
    res = UserVDAL.getUserV(uid)
    return Response(res,content_type='application/json')

@user.route('/setuser')
def setUser():
    # 获取数据
    id = request.args.get("id")
    name = request.args.get("name")
    qq = request.args.get("qq")
    sid = request.args.get("sid")
    sendEmail = True if request.args.get("sendEmail")=="true" else False
    autocard = True if request.args.get("autocard")=="true" else False
    # 创建对象
    user = User(id,sid,name,qq,autocard,sendEmail)
    res = 'false'
    if UserDAL.getUser(id) != "null":
        if UserDAL.setUser(user):
            res = 'true'
    else:
        if UserDAL.addUser(user):
            res = 'true'
    return Response(res)

@user.route('/setusersid')
def setUserSid():
    id = request.args.get("id")
    sid = request.args.get("sid")
    if UserDAL.setUserSid(id,sid):
        return Response("true")
    else:
        return Response("false")

@user.route('/getcarddata')
def getCardData():
    return Response(UserDAL.getCardData(),content_type='application/json')